package org.musicsweet.controller;

import com.alibaba.fastjson.JSON;
import org.musicsweet.anotation.AuthReq;
import org.musicsweet.entity.SysUser;
import org.musicsweet.result.ResultData;
import org.musicsweet.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@RestController
@RequestMapping("/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;

    @AuthReq
    @RequestMapping("/getSysUserById")
    public ResultData<SysUser> getSysUserById(@RequestBody SysUser sysUser) {
        return sysUserService.getUserById(sysUser);
    }

    @AuthReq
    @RequestMapping("/getUserList")
    public ResultData<List<SysUser>> getUserList(@RequestBody SysUser sysUser) {
        return sysUserService.getUserList(sysUser);
    }

    /**
     * 添加系统用户
     *   MultipartFile file
     * @param jsonStr
     * @return
     */
    @AuthReq
    @RequestMapping("/addSysUser")
    public ResultData addSysUser(String jsonStr, MultipartFile file, String token) {
        return sysUserService.addSysUser(JSON.parseObject(jsonStr,SysUser.class),file,token);
    }


    /**
     * 修改系统用户
     *
     * @param jsonStr
     * @return
     */
    @AuthReq
    @RequestMapping("/updateSysUser")
    public ResultData updateSysUser(String jsonStr,MultipartFile file, String token) {
        return sysUserService.updateSysUser(JSON.parseObject(jsonStr,SysUser.class),file,token);
    }


    /**
     * 删除系统用户
     *
     * @param sysUser
     * @return
     */
    @AuthReq
    @RequestMapping("/delSysUser")
    public ResultData delSysUser(@RequestBody SysUser sysUser) {
        return sysUserService.delSysUser(sysUser);
    }

    /**
     * 用户登录
     * @param sysUser
     * @return
     */
    @RequestMapping("/sysLogin")
    public ResultData sysLogin(@RequestBody SysUser sysUser) {
        return sysUserService.sysLogin(sysUser);
    }

    /**
     * 根据token获取用户信息
     * @return
     */
    @RequestMapping("/getSysUserByToken")
    public ResultData<SysUser> getSysUserByToken(String token){
        return sysUserService.getSysUserByToken(token);
    }

}
